<if condition="!empty($detail_content)">
<script language="javascript">
$(function(){
	$('form').form({ 
		success:function(data){
			var data = runJson(data);
			if(data.status == 0){
				alertText(data.info, 'error');
			}else{
				alertText(data.info, 'success', 'back');
			}
		}   
	});
});
</script>
<div class="box">
   	<form enctype="multipart/form-data" action="<eq name='ACTION_NAME' value='edit'>{:U('Product/update')}<else />{:U('Product/insert')}</eq>&ajax=true" method="post" >
     <div class="easyui-tabs">
    	<div title="产品基本信息">
    	<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table">
          <tr>
            <td class="label">产品分类：</td>
            <td>
            <div style="padding:6px; color:#0066CC;">{$position}</div>
            </td>
          </tr>
          <tr>
            <td class="label">产品名称：</td>
            <td>
            <input type="text" value="{$vo.name}" id="name" name="name" style="width:200px;" class="easyui-validatebox input" required="true" validType="length[2,20]" />
            </td>
          </tr>
          <tr>
            <td class="label">所属品牌：</td>
            <td>
            <select name="brand_id">
            <option value="0">请选择品牌</option>
            <volist name="brands" id="brand">
            <option value="{$key}" <if condition="$key eq $vo['brand_id']">selected</if>>{$brand}</option>
            </volist>
            </select>
            </td>
          </tr>
          <tr>
            <td class="label">仓库：</td>
            <td>
            <select name="store_id">
            <option value="0">请选择仓库</option>
            <volist name="stores" id="store">
            <option value="{$key}" <if condition="$key eq $vo['store_id']">selected</if>>{$store}</option>
            </volist>
            </select>
            <p class="notice">请选择存放产品的仓库，设置后不能随意修改。</p>
            </td>
          </tr>
          <tr>
            <td class="label">产品货号：</td>
            <td>
            <input type="text" value="{$vo.sn}" id="sn" name="sn" style="width:200px;" class="input" />
            </td>
          </tr>
          <tr>
            <td class="label">产品市场价：</td>
            <td>
            <input type="text" value="{$vo.market_price}" id="market_price" name="market_price" style="width:200px;" class="easyui-validatebox input" required="true" />
            </td>
          </tr>
          <tr>
            <td class="label">产品销售价：</td>
            <td>
            <input type="text" value="{$vo.price}" id="price" name="price" style="width:200px;" class="easyui-validatebox input" required="true" />
            </td>
          </tr>
          <tr>
            <td class="label">产品总库存数：</td>
            <td>
            <input type="text" value="{$vo.stock_number}" id="stock_number" name="stock_number" style="width:100px;" class="easyui-validatebox input" required="true" />
            <p class="notice">这是产品的总库存数，如果设置了产品的属性库存，产品总库存数将等于属性库存总和。</p>
            </td>
          </tr>
          <tr>
            <td class="label">产品属性：</td>
            <td>
            <if condition="empty($attributes)">
            <p class="notice">因产品分类<span style="padding:6px; color:#0066CC;">{$position}</span>没有绑定属性组或绑定的属性组没有可选属性，暂无属性可选。</p>
            <else />
            
            <dl>
            <volist name="attributes" id="attrs" key="k">
            <dt style="padding:5px;"><strong>{$attrs.name}：</strong></dt>
                <dd style="padding:5px 10px; border-bottom:1px dotted #ccc;">
                <if condition="empty($attrs['children'])">
                暂无属性！
                <else />
                <volist name="attrs['children']" id="attr_name">
                <label for="attr_{$key}" style="margin:0px 5px;"><input type="checkbox" value="{$key}" name="attr[{$k}][]" id="attr_{$key}" <if condition="in_array($key, $selectedAttribute)">checked</if> />&nbsp;{$attr_name}</label>
                </volist>
                </if>
                </dd>
            </volist>
            </dl>
            <eq name='ACTION_NAME' value='add'>
            <p class="notice">新增产品时请选择该款产品所有的属性，以供下一步设置属性库存。</p>
            <else />
            <p class="notice">添加或删除产品属性时，请重新设置部分属性的库存。</p>
            </eq>
            </if>
            </td>
          </tr>
          <tr>
            <td class="label">产品预览图片：</td>
            <td>
            <input type="file" name="img_url_file" id="img_url_file" />
            <eq name='ACTION_NAME' value='edit'><if condition="$vo['img_url']"><a href="{$vo.img_url}" target="_blank"><img src="__PUBLIC__/images/ui/icon_view.gif" border="0" /></a></if></eq>
            </td>
          </tr>
          <tr>
            <td class="label">备注：</td>
            <td>
            <textarea class="input" name="remark" id="remark" style="width:300px; height:100px;">{$vo.remark}</textarea>
            </td>
          </tr>
          <tr>
            <td class="label"></td>
            <td>
            <eq name='ACTION_NAME' value='add'><input type="hidden" name="cat_id" value="{$category.id}" /></eq>
            <eq name='ACTION_NAME' value='edit'><input type="hidden" name="id" value="{$vo.id}" /></eq>
            <input type="submit" class="button" value="提交" onclick="return $('form').form('validate')" />
            </td>
          </tr>
         </table>
         </div>
         <div title="产品规格">
         <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table">
        	<if condition="empty($attributes)">
            <tr><td colspan="2">
            <p class="notice">因产品分类<span style="padding:6px; color:#0066CC;">{$position}</span>没有绑定属性组或绑定的属性组无普通属性，暂无属性可选。</p>
            </td></tr>
            <else />
            <volist name="spec" id="attrs" key="k">
            <tr>
            <td class="label"><strong>{$attrs.name}：</strong></td>
            <td>
                <if condition="empty($attrs['children'])">
                暂无属性！
                <else />
                <volist name="attrs['children']" id="attr_name">
                <label for="spec_{$key}" style="margin:0px 5px;"><input type="checkbox" value="{$key}" name="spec[{$k}][]" id="spec_{$key}" <if condition="in_array($key, $selectedAttribute)">checked</if> />&nbsp;{$attr_name}</label>
                </volist>
                </if>
            </td>
            </tr>
            </volist>
          </if>
          <tr>
          	<td class="label"></td>
            <td></td>
          </tr>
          <tr>
            <td class="label"></td>
            <td>
            <input type="submit" class="button" value="提交" onclick="return $('form').form('validate')" />
            </td>
          </tr>
          </table>
         </div>
    </form>
</div>
<else />
<style type="text/css">
#cat-list { border:1px solid #eee; margin:15px; padding:10px; width:45%;}
#cat-list .tree-node { padding:5px 0px; border-bottom:1px dotted #eee; }
</style>
<script language="javascript">
$(function(){
	$("#cat-list").tree({
		url: '{:U("Product/select_category")}',
		animate:true,
		onClick:function(node){
			$('#cat_id').val(node.id);
		}
	});
});

function selectCategory(){
	var cat_id = $('#cat_id').val();
	if(!cat_id || cat_id == '0'){
		alertText('请选择产品分类！', 'error');
	}else{
		toUrl('{:U("Product/add")}'+'&cat_id='+cat_id);
	}
	return false;
}
</script>
<div class="box">
	<input type="hidden" id="cat_id" value="0" />
	<div class="easyui-panel" title="选择产品分类">
     <ul id="cat-list"></ul>
     <p style="margin:15px;">
     <a href="javascript:;" onclick="selectCategory()"><img src="__PUBLIC__/images/button/selectcategory.png" border="0" /></a>
     <span class="notice" style="margin-left:20px;">请选择产品分类并点击确定按钮进入产品信息添加页面。</span>
     </p>
    </div>
</div>
</if>